package com.tarena.lbs.business.servcie.impl;

import com.github.pagehelper.PageInfo;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.business.dao.repository.BusinessRepository;
import com.tarena.lbs.business.pojo.param.BusinessParam;
import com.tarena.lbs.business.pojo.po.BusinessPO;
import com.tarena.lbs.business.pojo.query.BusinessQuery;
import com.tarena.lbs.business.pojo.vo.BusinessStoreVO;
import com.tarena.lbs.business.pojo.vo.BusinessVO;
import com.tarena.lbs.business.servcie.BusinessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Slf4j
@Service
public class BusinessServiceImpl implements BusinessService {
    @Autowired
    private BusinessRepository  businessRepository;

    @Override
    public PageResult<BusinessVO> pageList(BusinessQuery query) {
        PageInfo<BusinessVO> list = businessRepository.selectList(query);

        PageResult<BusinessVO> pageResult = new PageResult<>();
        pageResult.setTotal(list.getTotal());
        pageResult.setObjects(list.getList());
        pageResult.setPageNo(list.getPageNum());
        pageResult.setPageSize(list.getPageSize());
        return pageResult;
    }

    @Override
    public void save(BusinessParam param) {
        BusinessPO  businessPO = new BusinessPO();
        BeanUtils.copyProperties(param,businessPO);
        businessPO.setBusinessName(param.getBusinessName());
        businessPO.setEntryTime(new Date());
        businessPO.setBusinessStatus(1);
        log.info("插入商家信息：{}", businessPO);
        businessRepository.insert(businessPO);
    }

    @Override
    public BusinessStoreVO busiStoreDetail(Integer businessId) {
        BusinessStoreVO businessStoreVO = businessRepository.detail(businessId);
        return businessStoreVO;
    }
}
